package cn.hacynn.nd.config;
import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @Author Hacynn
 * @Date 2024/6/5 8:38
 * @Version 1.0
 */

@Data
@Component
@ConfigurationProperties(prefix = "alipay")  //读取yml文件中alipay 开头的配置
public class AliPayConfiguration {
    // 支付宝的AppId
    private String appId;
    // 应用私钥
    private String appPrivateKey;
    // 支付宝公钥
    private String alipayPublicKey;
    // 支付宝通知本地接口的完整路径
    private String notifyUrl;


    @PostConstruct   // 类注入IOC时，会执行标记了@PostConstruct注解的方法，常用于初始化参数
    public void init() {
        // 设置参数（全局只需设置一次）
        Config config = new Config();
        config.protocol = "https";
        config.gatewayHost = "openapi-sandbox.dl.alipaydev.com";
        config.signType = "RSA2";
        config.appId = this.appId;
        config.merchantPrivateKey = this.appPrivateKey;
        config.alipayPublicKey = this.alipayPublicKey;
        config.notifyUrl = this.notifyUrl;
        Factory.setOptions(config);
        System.out.println("=======支付宝SDK初始化成功=======");
    }
}